package com.itheima.web;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author Xiao
 * @date 2021/8/29
 */
/**将针对不同的请求方式的处理逻辑封装到MyHttpServlet类中*/
public class MyHttpServlet implements Servlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        //根据请求方式的不同进行分别处理
        //1. 获取http请求对象
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        //2. 获取请求方式
        String method = request.getMethod();
        //3. 判断请求方式，分别进行逻辑处理
        if ("GET".equals(method)) {
            //get方式的处理逻辑
            doGet(servletRequest,servletResponse);
        } else if ("POST".equals(method)) {
            //post方式的处理逻辑
            doPost(servletRequest, servletResponse);
        }
    }

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    protected void doPost(ServletRequest servletRequest, ServletResponse servletResponse) {
    }

    protected void doGet(ServletRequest servletRequest, ServletResponse servletResponse) {
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
